package com.jmoney.luckeylink.controller;

import static io.restassured.RestAssured.given;
import io.restassured.RestAssured;
import io.restassured.config.SSLConfig;
import io.restassured.response.Response;

public class LekeU_Login_Controller {
	    static String token = null;
	    static int id =0;
		static String name = null;
	    static String id_card = null;
	    static String mobile = null;
	    static String occupation = null;
	    static String address = null;
	    static int type = 0;
	    static String blood_type = null;
	    static int id_card_photo_positive = 0;
	    static int id_card_photo_negative = 0;
	   /**
	    * 指定接口地址，获取登录的信息
	    * @param ApiUrl
	    * @return UserDetail
	    */
	   public static Object[] GetLoginInfo(String ApiUrl) throws Exception{

	       Response response = given()
	               .config((RestAssured.config().sslConfig(new SSLConfig().relaxedHTTPSValidation())))
	               .contentType("application/json")
	               .log().all()
	               .request()
	               .when()
	               .get(ApiUrl);

	       String Json = response.asString();
	       
	       int status_code = response.jsonPath().getInt("status_code");
	       String message = response.jsonPath().get("message");

	       if("ok".equals(message)){
	    	   token = response.jsonPath().get("data.token");
	       }

	       Object[] LoginInfo ={Json,status_code,message,token};
	       
	       return LoginInfo;
	   }
	   
	   /**
	    * 指定接口地址，获取登录用户的信息
	    * @param ApiUrl
	    * @return UserDetail
	    */
	   public static Object[] GetUserDetail(String ApiUrl) throws Exception{

	       Response response = given()
	               .config((RestAssured.config().sslConfig(new SSLConfig().relaxedHTTPSValidation())))
	               .contentType("application/json")
	               .log().all()
	               .request()
	               .when()
	               .get(ApiUrl);

	       String Json = response.asString();
	       
	       int status_code = response.jsonPath().getInt("status_code");
	       String message = response.jsonPath().get("message");

	       if("ok".equals(message)){
	    	   id = response.jsonPath().getInt("data.id");
		       name = response.jsonPath().get("data.name");
		       id_card = response.jsonPath().get("data.id_card");
		       mobile = response.jsonPath().get("data.mobile");
		       occupation = response.jsonPath().get("data.occupation");
		       address = response.jsonPath().get("data.address");
		       type = response.jsonPath().getInt("data.type");
		       blood_type = response.jsonPath().get("data.blood_type");
		       id_card_photo_positive = response.jsonPath().getInt("data.id_card_photo_positive");
		       id_card_photo_negative = response.jsonPath().getInt("data.id_card_photo_negative");
	       }

	       Object[] UserDetail ={Json,status_code,message,id,name,id_card,mobile,occupation,address,type,blood_type,id_card_photo_positive,id_card_photo_negative};
	       
	       return UserDetail;
	   }
}
